<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title th:text="${question.title}"></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="/css/bootstrap.css"/>
    <link rel="stylesheet" href="/css/bootstrap-theme.css"/>
    <link rel="stylesheet" href="/css/forum.css"/>
    <link rel="stylesheet" href="/css/editormd.preview.min.css">
    <script src="/js/jquery-3.5.1.min.js"></script>
    <script src="/js/bootstrap.min.js" type="application/javascript"></script>
    <script src="/js/forum.js"></script>
    <script src="/js/moment.js"></script>
    <script src="/js/editormd.min.js"></script>
    <script src="/js/lib/marked.min.js"></script>
    <script src="/js/lib/prettify.min.js"></script>
</head>
<body>
<div th:insert="~{navigation::nav}"></div>
<div class="container-fluid main profile">
    <div class="row">
        <!--左边主要内容-->
        <div class="col-lg-9 col-md-9  col-sm-9 col-xs-9">
            <!--正文-->
            <div class="col-lg-12 col-md-12  col-sm-12 col-xs-12">
                <h4 class="question-title"><span th:text="${question.title}"></span> </h4>
                <span class="text-desc">
                作者:<span th:text="${question.user.name}"></span> |
                发布时间:<span th:text="${#dates.format(question.gmtCreate,'yyyy-MM-dd HH:mm')}"></span> |
                阅读数:<span th:text="${question.viewCount}"></span>
                </span> |  &nbsp;<span class="glyphicon glyphicon-thumbs-up icon" th:data-id="${question.id}"
                                      th:data-userid="${session.user!=null?session.user.id:0}" onclick="like(this)"></span>
                            <span id="likeCount" th:text="${question.likeCount}"></span>
                </span>
                <script>
                    function like(e) {
                        var id=e.getAttribute("data-id");
                        var userid = e.getAttribute("data-userid")
                        console.log(id)
                        console.log(userid);
                        var likeCount = $("#likeCount").text();
                        likeCount=parseInt(likeCount)
                        $.ajax({
                            type:"POST",
                            url:"/like/"+id,
                            data: {
                                "userid":userid},
                            success:function (data) {
                                console.log(data);
                                if(data=="1"){
                                    alert("已点赞!请勿重复点赞!!")
                                }
                                else if(data=="2"){
                                    alert("未登录用户不能点赞!请登录!")
                                }
                                else{
                                    $("#likeCount").html(likeCount+1);
                                    alert("点赞成功!")
                                }
                            }
                        });
                    }
                </script>
            </span>
                <hr>
                <!--内容-->
                <div class="col-lg-12 col-md-12  col-sm-12 col-xs-12" id="description-view">
                    <textarea style="display:none;" th:text="${question.description}"></textarea>
                </div>
                <script type="text/javascript">
                    $(function () {
                        editormd.markdownToHTML("description-view", {});
                    });
                </script>
                <!--标签-->
                <hr class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    <span style="color: #3c763d">标签:</span>
                    <span class="question-tag" th:each="tag : ${question.tag.split(',')}">
                        <a th:href="@{/(page=1,tag=${tag})}"
                           th:text="${tag}" class="community-tag">
                        </a>
                    </span>
                    <button class="btn btn-default" style="float: right">
                            <span class="glyphicon glyphicon-thumbs-up icon active" th:text="点赞该文章" style="color: #00a8c6"
                                  th:data-id="${question.id}" th:data-userid="${session.user!=null?session.user.id:0}" onclick="like(this)">
                            </span></button>
                </div>
                <!--编辑-->
                <hr class="col-lg-12 col-md-12  col-sm-12 col-xs-12">
                <a  th:href="@{'/publish/'+${question.id}}" class="community-menu" th:if="${session.user!=null && session.user.id==question.creator}">
                    <span class="glyphicon glyphicon-pencil">编辑文章</span>
                </a>
                <a id="ab" href="#" th:if="${(session.user!=null && session.user.privilege!=null) || (session.user!=null && session.user.id==question.creator)}">
                    <span style="color: red" class="glyphicon glyphicon-alert" id="delete" th:data-id="${question.id}" onclick="delete1(this)">删除</span>
                </a>
                <script>
                    function delete1(e) {
                        var attribute = e.getAttribute("data-id");
                        var b = confirm("是否确认删除");
                        if(b){
                            $.ajax({
                                type:"GET",
                                url:"/delete/"+attribute,
                            });
                            $("#ab").attr("href","/");
                            alert("删除成功")
                        }
                    }
                </script>
            </div>
            <!--回复-->
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <h4>
                    <span th:text="${question.commentCount}"></span> 个回复
                </h4>
                <hr class="col-lg-12 col-md-12 col-sm-12 col-xs-12 comment-sp">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 comments" th:each="comment : ${comments}">
                    <div class="media">
                        <div class="media-left" >
                            <a href="#">
                                <img class="media-object img-rounded"
                                     th:src="${comment.user.avatarUrl}">
                            </a>
                        </div>
                        <div class="media-body" th:id="${'comment-body-'+comment.id}">
                            <h5 class="media-heading">
                                <span th:text="${comment.user.name}"></span>
                            </h5>
                            <div th:text="${comment.content}"></div>
                            <div class="menu">
                                <span id="CommentLikeCount" th:text="${comment.likeCount}" class="glyphicon glyphicon-thumbs-up icon" th:data-userid="${session.user!=null?session.user.id:0}" th:data-commentid="${comment.id}" onclick="CommentLike(this)">

                                </span>

                                <script>
                                    function CommentLike(e) {
                                        var userid=e.getAttribute("data-userid");
                                        var commentid = e.getAttribute("data-commentid")
                                        console.log(userid)
                                        console.log(commentid);
                                        var CommentLikeCount = $("#CommentLikeCount").text();
                                        CommentLikeCount=parseInt(CommentLikeCount)
                                        $.ajax({
                                            type:"POST",
                                            url:"/commentlike",
                                            data: {
                                                "userid":userid,
                                                "commentid":commentid
                                            },
                                            success:function (data) {
                                                console.log(data);
                                                if(data=="1"){
                                                    alert("已点赞!请勿重复点赞!!")
                                                }
                                                else if(data=="2"){
                                                    alert("未登录用户不能点赞!请登录!")
                                                }
                                                else{
                                                    $("#CommentLikeCount").html(CommentLikeCount+1);
                                                    alert("点赞成功!")
                                                    window.location.reload();
                                                }
                                            }
                                        });
                                    }
                                </script>

                                <span th:data-id="${comment.id}"
                                      onclick="collapseComments(this)" class="comment-icon">
                                    <span class="glyphicon glyphicon-thumbs-up icon" th:data-id="${question.id}"
                                          th:data-userid="${session.user!=null?session.user.id:0}" onclick="like(this)"></span>
                                    <span id="likeCount" th:text="${question.likeCount}"></span>
                                    <span th:text="${comment.commentCount}" style="margin-left: -5px"></span>
                                </span>
                                <span class="pull-right"
                                      th:text="${#dates.format(comment.gmtCreate,'yyyy-MM-dd HH:mm')}">
                                </span>
                            </div>
                            <!--二级评论a-->
                            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 collapse sub-comments"
                                 th:id="${'comment-'+comment.id}">
                                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                                    <input type="text" class="form-control" placeholder="评论一下……"
                                           th:id="${'input-'+comment.id}">
                                    <button type="button" class="btn btn-success pull-right" onclick="comment(this)"
                                            th:data-id="${comment.id}">评论
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!--回复输入框-->
            <div class="col-lg-12 col-md-12  col-sm-12 col-xs-12" id="comment_section">
                <h4>
                    提交回复
                </h4>
                <hr class="comment-sp" style="margin-bottom: 5px">
                <div class="media comment-sp">
                    <div class="media-left">
                        <a href="#">
                            <img class="media-object img-rounded" width="42px" height="42px"
                                 th:src="${session.user!=null?session.user.avatarUrl:'/img/default.png'}">
                        </a>
                    </div>
                    <div class="media-body">
                        <h4 class="media-heading">
                            <span th:text="${session.user!=null?session.user.name:'未登录用户'}" ></span>
                        </h4>
                    </div>
                </div>
                <input type="hidden" id="question_id" th:value="${question.id}">
                <textarea class="form-control comment" rows="6" id="comment_content"></textarea>
                <button type="button" class="btn btn-success btn-comment" onclick="post()">回复</button>
            </div>
        </div>
        <!--右边信息块-->
        <div class="col-lg-3 col-md-3  col-sm-3 col-xs-3">
            <div class="col-lg-12 col-md-12  col-sm-12 col-xs-12">
                <h4>发起人</h4>
                <div class="media">
                    <div class="media-left">
                        <a href="#">
                            <img class="media-object img-circle" width="42px" height="42px"
                                 th:src="${question.user.avatarUrl}">
                        </a>
                    </div>
                    <div class="media-body">
                        <h4 class="media-heading">
                            <span th:text="${question.user.name}" ></span>
                        </h4>
                    </div>
                </div>
            </div>
            <!--二珂我老婆-->
            <hr class="col-lg-12 col-md-12  col-sm-12 col-xs-12">
            <div class="col-lg-12 col-md-12  col-sm-12 col-xs-12">
                <h4 style="margin-left: 109px">火影忍者</h4>
                <img src="/img/huo.jpg" width="100%">
            </div>
            <!--相关问题-->
            <hr class="col-lg-12 col-md-12  col-sm-12 col-xs-12">
            <div class="col-lg-12 col-md-12  col-sm-12 col-xs-12">
                <h4>相关问题</h4>
                <ul class="question-related">
                    <li th:each="related : ${relatedQuestions}">
                        <a th:href="@{'/question/'+${related.id}}" th:text="${related.title}"></a>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</div>
<div th:insert="~{footer::foot}"></div>
</body>
</html>